//
//  YCInterviewDisplayViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/5.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  预约考试第一个界面，展示各科目预情况

#import "YCInterviewDisplayViewController.h"
#import "YCInterviewDisplayCell.h"
#import "YCInterviewDisplayModel.h"
#import "YCCommitInterviewViewController.h"

@interface YCInterviewDisplayViewController ()<UITableViewDelegate,UITableViewDataSource>

/** tableView */
@property (nonatomic, strong) UITableView *tableView;
/** 数据  */
@property (nonatomic, strong) NSArray *dataArray;
@end

@implementation YCInterviewDisplayViewController


//- (NSArray *)dataArray
//{
//    if (!_dataArray) {
//        YCInterviewDisplayModel *model = [[YCInterviewDisplayModel alloc] init];
//        model.courseName = @"科目一";
//        model.courseDetail = @"驾驶员理论考试";
//        model.interviewStatus = InterviewStatusTypeComplete;
//        
//        YCInterviewDisplayModel *model1 = [[YCInterviewDisplayModel alloc] init];
//        model1.courseName = @"科目二";
//        model1.courseDetail = @"场地驾驶技能考试";
//        model1.interviewStatus = InterviewStatusTypeSucceed;
//        
//        YCInterviewDisplayModel *model2 = [[YCInterviewDisplayModel alloc] init];
//        model2.courseName = @"科目三";
//        model2.courseDetail = @"道路驾驶技能考试";
//        model2.interviewStatus = InterviewStatusTypeEnable;
//        
//        YCInterviewDisplayModel *model3 = [[YCInterviewDisplayModel alloc] init];
//        model3.courseName = @"科目四";
//        model3.courseDetail = @"安全文明驾驶常识考试";
//        model3.interviewStatus = InterviewStatusTypeDisable;
//        
//        _dataArray = @[model,model1,model2,model3];
//    }
//    return _dataArray;
//}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.yc_width, self.view.yc_height-64) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    }
    return _tableView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self yc_addBackBarButtonItem];
    self.navigationItem.title = @"预约考试";
    
    [self.view addSubview:self.tableView];
    self.tableView.contentInset = UIEdgeInsetsMake(9.5, 0, 0, 0);//15 = 9.5 + 5.5
    self.tableView.rowHeight = 117;// 106+间距11(上下各5.5)
    
    YCWeakSelf;
    self.tableView.mj_header = [YCRefreshHeader headerWithRefreshingBlock:^{
        [weakSelf loadData];
    }];
    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 数据处理
- (void)loadData
{
    NSDictionary *params = @{
                             @"uid":@"1",
                             @"token":accessToken_Test,
                             };
    [[YCNetworManager shareManager] postWithUrl:YCAPIInterviewExamList params:params success:^(NSURLSessionDataTask *task, ServiceResponse *response) {
        NSArray *resultDictArray = response.data[@"course"];
        self.dataArray = [YCInterviewDisplayModel yc_objectArrayWithKeyValuesArray:resultDictArray];
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        YCLog(@"%@",error.localizedDescription);
        [self.tableView.mj_header endRefreshing];
    }];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCWeakSelf
    YCInterviewDisplayCell *cell = [YCInterviewDisplayCell tableViewCellWithTableView:tableView withIndexPath:indexPath interviewStatusButtonActionBlock:^{
        // 点击详情介绍按钮处理处
        YCInterviewDisplayModel *mode = weakSelf.dataArray[indexPath.row];
        YCLog(@"%@",mode.cname);
        
        // push
        [self.navigationController pushViewController:[[YCCommitInterviewViewController alloc] init] animated: YES];
    }];
    cell.itemModel = self.dataArray[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate



#pragma mark - 点击事件




@end
